<template>
<table>
    <tr>
        <td>投资名称</td>
        <td><input type="text" v-model="info.Iname"></td>
    </tr>
    <tr>
        <td>投资总金额</td>
        <td><input type="text" v-model="info.Isum"></td>
    </tr>
    <tr>
        <td colspan="2"><button @click="Update">修改</button></td>
    </tr>
</table>
</template>
<script setup lang="ts">
import { useRoute } from 'vue-router';
import {ref,onMounted}from 'vue'
import axios from 'axios';
const route = useRoute();
const Iid= route.params.Iid;
console.log(Iid);
const info=ref(
    {
        Iname:'',
        Isum:''
    }
)
onMounted(()=>{
    ShowById()
})
const ShowById=()=>{
    axios.get('https://localhost:44382/api/Lx/ShowById',
        {
            params:{
                Iid:Iid
            }
        }
    )
    .then(res=>{
        info.value.Iname=res.data[0].Iname;
        info.value.Isum=res.data[0].Isum;
    })
    .catch(err=>{
        console.log(err);
    })
}
const Update=()=>{
    axios.get('https://localhost:44382/api/Lx/Update',
        {
            params:{
                Iid:Iid,
                Iname:info.value.Iname,
                Isum:info.value.Isum
            }
        }
    )
    .then(res=>{
        if(res.data>0){
            alert("修改成功")
            location.href="ShowInvest"
        }
        else{
            alert("修改失败")
            location.href="ShowInvest"
        }
    })
    .catch(err=>{
        console.log(err);
    })
}

</script>